﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace DongFangGuoKai.WMSPlatform.Extensions
{
    /// <summary>
    /// Cors扩展
    /// </summary>
    public static class CorsExtension
    {
        /// <summary>
        ///  注入Cors
        /// </summary>
        /// <param name="builder"></param>
        public static void AddCorsExtend(this WebApplicationBuilder builder)
        {
            builder.Services.AddCors(options =>
            {
                options.AddPolicy(name: "MyAllowSpecificOrigins",
                                  policy =>
                                  {
                                      policy.AllowAnyOrigin()
                                            .AllowAnyHeader()
                                            .AllowAnyMethod();

                                  });
            });

        }

        /// <summary>
        /// Cors中间件
        /// </summary>
        /// <param name="builder"></param>
        public static void UseCorsExtend(this WebApplication builder)
        {
            builder.UseCors("MyAllowSpecificOrigins");

        }

    }
}
